const { Controller } = require('egg')

class ApiController extends Controller {
  async index() {
    const { ctx } = this
    const { query } = ctx

    const moduleName = query.module.split('/').pop()
    const module = await ctx.model.Module.findOne({
      moduleName,
    }).then((doc) => {
      if (!doc) throw '未知模块'
      return doc
    })

    ctx.body = {
      success: true,
      status: 200,
      message: 'Success',
      data: module.moduleData,
    }
  }
}

module.exports = ApiController
